<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
      
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="saleOrderId" label="主键">
          <a-input placeholder="请输入主键" v-model="model.saleOrderId" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="saleOrderGoodsId" label="商品主键">
          <a-input placeholder="请输入商品主键" v-model="model.saleOrderGoodsId" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="saleOrderUserId" label="客户主键">
          <a-input placeholder="请输入客户主键" v-model="model.saleOrderUserId" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="saleOrderRepoId" label="仓库主键">
          <a-input placeholder="请输入仓库主键" v-model="model.saleOrderRepoId" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="saleOrderNumber" label="订单号">
          <a-input placeholder="请输入订单号" v-model="model.saleOrderNumber" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="saleOrderCount" label="销售数量">
          <a-input-number v-model="model.saleOrderCount"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="saleOrderTotal" label="总价">
          <a-input-number v-model="model.saleOrderTotal"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="saleOrderStatus" label="订单状态(0:下单 1:确认收货 2:退货)">
          <a-input-number v-model="model.saleOrderStatus"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="saleOrderDescription" label="描述">
          <a-input placeholder="请输入描述" v-model="model.saleOrderDescription" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deleted" label="是否删除">
          <a-input placeholder="请输入是否删除" v-model="model.deleted" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createdBy" label="创建人">
          <a-input placeholder="请输入创建人" v-model="model.createdBy" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createdTime" label="创建时间">
          <a-date-picker showTime valueFormat='YYYY-MM-DD HH:mm:ss' v-model="model.createdTime" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="updatedBy" label="更新人">
          <a-input placeholder="请输入更新人" v-model="model.updatedBy" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="updatedTime" label="更新时间">
          <a-date-picker showTime valueFormat='YYYY-MM-DD HH:mm:ss' v-model="model.updatedTime" />
        </a-form-model-item>
		
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import moment from "moment"

  export default {
    name: "SaleOrderModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        saleOrderId:[{ required: true, message: '请输入主键!' }],
        saleOrderGoodsId:[{ required: true, message: '请输入商品主键!' }],
        saleOrderUserId:[{ required: true, message: '请输入客户主键!' }],
        saleOrderRepoId:[{ required: true, message: '请输入仓库主键!' }],
        saleOrderCount:[{ required: true, message: '请输入销售数量!' }],
        },
        url: {
          add: "/manager/saleOrder/add",
          edit: "/manager/saleOrder/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        //初始化默认值
        this.edit({});
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.$refs.form.clearValidate();
      },
      handleOk () {
        const that = this;
        // 触发表单验证
         this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
             return false;
          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>